﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BUS;
using DTO;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace FastDeal
{
    public partial class Template : System.Web.UI.MasterPage
    {
        //Sanh 
        DiaPhuong _madiaphuong = new DiaPhuong();

        List<DiaPhuong> dp = new List<DiaPhuong>();
        DiaPhuong_BUS db1 = new DiaPhuong_BUS();
        protected void Page_Load(object sender, EventArgs e)
        {
            //dp = db1.LayDanhSach_DiaPhuong();
            //DropDownList1.DataSource = dp;
            //DropDownList1.DataValueField = "MaDiaPhuong";
            //DropDownList1.DataTextField = "TenDiaPhuong";
            //DropDownList1.DataBind();
           
            //foreach (DiaPhuong d in dp)
            //{
            //    DropDownList1.Items.Add(d.TenDiaPhuong);
            //}
            //DropDownList1.DataBind();
        }

        //protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    int index = int.Parse(DropDownList1.SelectedIndex.ToString());
        //    DiaPhuong d = dp[index];
        //    string url = "~/HienThiTheoKhuVuc.aspx?MaDiaPhuong=" + d.MaDiaPhuong.ToString();
        //    Response.Redirect(url);
        //}
  

        protected void Button1_Click(object sender, EventArgs e)
        {
            Session["theme"] = "Theme1";
            Response.Redirect(Request.Url.ToString());
        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["theme"] == null)
            {
                Session["theme"] = "Theme1";
            }
            Page.Theme = Session["theme"].ToString();
        }

        protected void btnGiaoDien1_Click(object sender, EventArgs e)
        {
            Session["theme"] = "Theme1";
            Response.Redirect(Request.Url.ToString());
        }

        protected void btnGiaoDien2_Click(object sender, EventArgs e)
        {
            Session["theme"] = "Theme2";
            Response.Redirect(Request.Url.ToString());
        }

        protected void btnOKNhapEmail_Click(object sender, EventArgs e)
        {
            try
            {
                string emailPattern = @"^(([^<>()[\]\\.,;:\s@\""]+"
                      + @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@"
                      + @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
                      + @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"
                      + @"[a-zA-Z]{2,}))$";
                Regex emailReg = new Regex(emailPattern);
                bool isValid = emailReg.IsMatch(txtEmail.Text);
                if (isValid == true)
                {

                    Email_KhuyenMai_BUS db = new Email_KhuyenMai_BUS();
                    Email_KhuyenMai email = new Email_KhuyenMai();
                    email.Email = txtEmail.Text;
                    email.isDelete = 0;
                    db.Them_Email(email);
                    txtEmail.Text = string.Empty;
                    System.Web.HttpContext.Current.Response.Write("<SCRIPT language='javascript'>alert('Thêm email thành công!')</SCRIPT>");
                    
                }
                else
                {
                    System.Web.HttpContext.Current.Response.Write("<SCRIPT language='javascript'>alert('Email không đúng định dạng!')</SCRIPT>");
                }
            }
            catch (Exception ex)
            {
                
            }
        }

        protected void txtEmail_TextChanged(object sender, EventArgs e)
        {

        }

    }
}
